class Node {
  constructor(element, next) {
    this.element = element
    this.next = next || null
  }
}

class LinkedListCycle {
  isCycle(head) {
    let p1 = head
    let p2 = head
    while(p2 != null && p2.next != null) {
      p1 = p1.next
      p2 = p2.next.next
      if(p1.element == p2.element) {
        // console.log(p1, p2)
        return true
      }
    }
    return false
  }
}


let node1 = new Node(5)
let node2 = new Node(6)
let node3 = new Node(3)
let node4 = new Node(8)
let node5 = new Node(1)
node1.next = node2;
node2.next = node3;
node3.next = node4;
node4.next = node5;
node5.next = node2;

let cycle = new LinkedListCycle()

console.log(cycle.isCycle(node1))